package com.cn.hotel.service.impl;

import com.cn.hotel.dao.ICompanyDao;
import com.cn.hotel.dao.ICompanyInformationDao;
import com.cn.hotel.dao.Impl.CompanyImpl;
import com.cn.hotel.dao.Impl.CompanyInformationImpl;
import com.cn.hotel.model.CompanyInformationModel;
import com.cn.hotel.model.CompanyModel;
import com.cn.hotel.service.ICompanyInformationService;
import redis.clients.jedis.Jedis;

public class CompanyInformationServiceImpl implements ICompanyInformationService {
    /**
     * 前端获取公司信息逻辑代码
     * @return
     */
    @Override
    public CompanyInformationModel getCompanyInformationModel() {
        ICompanyInformationDao companyInformationDao = new CompanyInformationImpl();
        CompanyInformationModel companyInformationModel = new CompanyInformationModel();
        //首先判断jedis里面是否含有数据，如果存在 直接从radis拿取，如果没有数据 则查询数据库
         Jedis jedis = new Jedis();
         if (jedis.exists("company_phone")){
             companyInformationModel.setLogo(jedis.get("company_logo"));
             companyInformationModel.setAd(jedis.get("company_ad"));
             companyInformationModel.setNet(jedis.get("company_net"));
             companyInformationModel.setVersion(jedis.get("company_version"));
             companyInformationModel.setQrCode(jedis.get("company_qr_code"));
             companyInformationModel.setIntroduce(jedis.get("company_introduce"));
             companyInformationModel.setFax(jedis.get("company_fax"));
             companyInformationModel.setPhone(jedis.get("company_phone"));
             companyInformationModel.setEmail(jedis.get("company_email"));
             companyInformationModel.setAddress(jedis.get("company_address"));
             System.out.println("redis");
         }else {
             companyInformationModel = companyInformationDao.getCompanyInformationModel();
             jedis.set("company_logo",companyInformationModel.getLogo());
             jedis.set("company_ad",companyInformationModel.getAd());
             jedis.set("company_net",companyInformationModel.getNet());
             jedis.set("company_version",companyInformationModel.getVersion());
             jedis.set("company_qr_code",companyInformationModel.getQrCode());
             jedis.set("company_introduce",companyInformationModel.getIntroduce());
             jedis.set("company_fax",companyInformationModel.getFax());
             jedis.set("company_phone",companyInformationModel.getPhone());
             jedis.set("company_email",companyInformationModel.getEmail());
             jedis.set("company_address",companyInformationModel.getAddress());
             System.out.println("sql");
         }
         return companyInformationModel;
    }

    @Override
    public CompanyInformationModel getinformation() {
        ICompanyInformationDao companyInformationDao = new CompanyInformationImpl();
        CompanyInformationModel companyInformationModel = new CompanyInformationModel();
        //首先判断jedis里面是否含有数据，如果存在 直接从radis拿取，如果没有数据 则查询数据库
        Jedis jedis = new Jedis();
        if (jedis.exists("company_phone")){
            companyInformationModel.setLogo(jedis.get("company_logo"));
            companyInformationModel.setAd(jedis.get("company_ad"));
            companyInformationModel.setNet(jedis.get("company_net"));
            companyInformationModel.setVersion(jedis.get("company_version"));
            companyInformationModel.setQrCode(jedis.get("company_qr_code"));
            companyInformationModel.setIntroduce(jedis.get("company_introduce"));
            companyInformationModel.setFax(jedis.get("company_fax"));
            companyInformationModel.setPhone(jedis.get("company_phone"));
            companyInformationModel.setEmail(jedis.get("company_email"));
            companyInformationModel.setAddress(jedis.get("company_address"));
            System.out.println("redis");
        }else {
            companyInformationModel = companyInformationDao.getInformation();
            jedis.set("company_logo",companyInformationModel.getLogo());
            jedis.set("company_ad",companyInformationModel.getAd());
            jedis.set("company_net",companyInformationModel.getNet());
            jedis.set("company_version",companyInformationModel.getVersion());
            jedis.set("company_qr_code",companyInformationModel.getQrCode());
            jedis.set("company_introduce",companyInformationModel.getIntroduce());
            jedis.set("company_fax",companyInformationModel.getFax());
            jedis.set("company_phone",companyInformationModel.getPhone());
            jedis.set("company_email",companyInformationModel.getEmail());
            jedis.set("company_address",companyInformationModel.getAddress());
            System.out.println("sql");
        }
        return companyInformationModel;
    }
}
